package com.zcx.qshop.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;
import com.zcx.qshop.entity.Good;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/9/15 0015.
 */
@HttpInlet(Conn.INLET_JSON_EVALUATE)
public class JsonEvaluateAsyGet extends QSAsyGet<List<Good>> {

    public String orderid;

    public JsonEvaluateAsyGet(String orderid, AsyCallBack asyCallBack) {

        super(asyCallBack);

        this.orderid = orderid;

    }

    @Override
    public List<Good> parser(JSONObject object) {

        List<Good> list = new ArrayList<>();

        if(object.optString("message").equals("1")){

            JSONArray array = object.optJSONArray("goodslist");

            for (int i = 0 ; i < array.length() ; i ++){

                JSONObject o = array.optJSONObject(i);

                Good good = new Good();

                good.pid = o.optString("pid");

                good.picurl = Conn.SERVICE + o.optString("picurl");

                good.title = o.optString("title");

                good.price = o.optString("price");

                good.unit = o.optString("unit");

                list.add(good);

            }

            return list;

        }

        return null;

    }

}
